apiready = function(){
seajs.use(['../../V',"../../api","../../jquery","../../app","../../service"],function(V,$api,$,$app,service){
	var vm = {
		el: '.person-shop',
	  	data: {
			unionid: $api.getStorage("shop_unionid"),
			is_shop: '',
			orderList: '',
			payActive: false,
			shareActive: false,
			openShopActive: true,
			num: $api.getStorage("shop_data").invite_num,
			is_shop: $api.getStorage("shop_data").is_seller,
			isOpenShop: $api.getStorage("shop_data").is_store == 0 ? false : true,
			popIsShop: $api.getStorage("shop_data").is_store == 0 ? true : false
	  	},
	  	methods:{
	  		init: function(et){
	  			this.getList();
	  		},
	  		getList: function(et){

	  		},
	  		//--我要开店
			goOpenShop: function(et){
				if(this.is_shop == 1){
					api.openWin({
						name: 'my_shop',
						url: '../my_shop/my_shop.html',
						reload: true
					});
				}else{
					if(!this.isOpenShop){
						//this.openShopMainShow();
						this.popIsShop = true;
					}else{
						api.openWin({
							name: 'openShop',
		              		url: 'widget://src/Shop/shop/shop.html',
		              		reload: true
						});
					}
				}
			},
	  		//--关闭frame
	  		closeFrame: function(){
	  			api.closeFrame();
	  		},
	  		//--关闭窗口
			closeOpenShop: function(){
				api.closeWin();
			},
			//--显示开店选择
			openShopShow: function(){
				this.payActive = false;
				this.shareActive = false;
				this.openShopActive = true;
			},
			//--显示分享
			shareShow: function(){
				this.payActive = false;
				this.shareActive = true;
				this.openShopActive = false;
			},
			//--显示支付
			payShow: function(){
				this.payActive = true;
				this.shareActive = false;
				this.openShopActive = false;
			},
			//--开店立即支付
			openShopPay: function(et){
				var self = this;
  				this.pay_id = +et.currentTarget.dataset.id;
  				this.payIndex = +et.currentTarget.dataset.index;
  				$app.ajax(service.openShopPay,{
					data: {
						values: {
							unionid: self.unionid,
							pay_type: self.pay_id
						}
					}
				},function (res) {
					//console.log("go_pay: "+JSON.stringify(res));
					if(res.code == 0){
						if(self.pay_id == 2){
							//--支付宝支付
							var aliPayPlus = api.require('aliPayPlus');
			              	aliPayPlus.payOrder({
			                  	orderInfo: res.data
			              	}, function(ret, err) {
				                // 9000成功
				                if(ret.code == 9000){
				                  	//支付成功
				                  	self.isOpenShop = true;
				                  	self.goOpenShop();
				                }else{
				                	//--取消支付
				                	$app.toast('支付失败！');
				                }
	              			});
						}else if(self.pay_id == 3){
							//--微信支付
							var wxPay = api.require('wxPay');
				            wxPay.payOrder({
				                orderId: res.data.prepayid,
				                mchId:  res.data.partnerid,
				                nonceStr: res.data.noncestr,
				                timeStamp: res.data.timestamp,
				                package: res.data.package,
				                sign: res.data.sign,
				                apiKey: res.data.appid
				            }, function(ret, err) {
				            	//console.log(self.money);
				                if (ret.status) {
				                    //支付成功
				                    self.isOpenShop = true;
				                    self.goOpenShop();
				                } else {
			                		$app.toast('支付失败！');
				                }
				            });
						}
					}
				});
			},
			//--邀请好友
			openShopShare: function(et){
				var self = this;
				var wx = api.require('wx');
				var toWhere = '';
				var type = +et.currentTarget.dataset.type;
				if (type == 1) {
					// 分享给朋友
					toWhere = 'session';
				} else if (type == 2) {
					// 分享到朋友圈
					toWhere = 'timeline';
				}
				$app.ajax(service.openShopShare,{
					data: {
						values: {
							unionid: self.unionid,
						}
					}
				},function (res) {
					console.log("person_share："+JSON.stringify(res));
					if (res.code == 0) {
						var url = res.data;
						wx.shareWebpage({
						    scene: toWhere,
						    title: '你的好友邀请你帮忙开店',
						    description: '你的好友邀请你帮忙开店，点一下链接即可，谢谢',
						    contentUrl: url
						}, function(ret, err) {
						    if (ret.status) {
						        $app.toast('分享成功');
						        self.closeFrame();
						    } else {
								$app.toast('分享失败');
						    }
						});
					} else {
						api.toast({
						    msg: '获取分享链接失败',
						    duration: 2000,
						    location: 'bottom'
						});
					}
				});
			},
			//--邀请码
			openShopCode: function(et){
				var self = this;
				var val = this.$refs.openShopCodeValue.value.trim();
				if(val == ''){
					$app.toast("请填写邀请码！");
					return;
				}
				$app.ajax(service.openShopCode,{
					data: {
						values: {
							unionid: self.unionid,
							invite_code: val
						}
					}
				},function (res) {
					console.log("code："+JSON.stringify(res));
					if(res.code == 0) {
						self.closeFrame();
						self.isOpenShop = true;
	                    self.goOpenShop();
					}else{
						$app.toast(res.message);
					}
				});
			}
	  	},
	  	mounted:function() {
	  		var self = this;
	  	},
	  	created: function(){
	  		this.num = api.pageParam.num;
	  		this.init();
	  	}
	};

	var even = function() {}
	var newVue = new Vue(vm);
	even();
});
}
